<div class="grid_15" id="newStyles">
<?php if($this->msg) { ?>
	<span class="helperText"><?php print($this->msg); ?></span>
<?php }

if('' != trim($this->ci->getRegistrarKey())) { ?>
	<div class="policyNotice">
		<p>This course was created by an automated import of campus data. Making changes to the title and cross listings manually is not recommended.</p>
		<p>If you need assistance with the listing of this course, please contact <a href="mailto:<?php print(Rd_Registry::get('root:supportEmail')); ?>">reserves staff</a>.</p>
	</div>
<?php } ?>	

<div class="cancelNavigation">[<a href="./?cmd=editClass&ci=<?php print($this->ci->getId()); ?>">Return to Edit Class</a>]</div>
<h2 class="formHeader grid_5">TITLES & CROSSLISTINGS</h2>
<form class="bordered clearing bottomMargin" action="./" method="post">
	<input type="hidden" name="cmd" value="editCrossListings"/>
	<input type="hidden" name="ci" value="<?print($this->ci->getCourseInstanceID());?>"/>
	<table class="paddedCells fullWidth">
		<tr class="headingRow">
			<th>Primary</th>
			<th>Department</th>
			<th>Number</th>
			<th>Section</th>
			<th>Title</th>
			<th>Key</th>
			<th>Remove</th>
		</tr>
	<?php 
$classes = array_merge(array($this->ci->course), $this->ci->crossListings);
$primaryId = $this->ci->getCourseAliasID();
$deletable = Account_Rd::atLeastStaff() && count($this->ci->crossListings) == 0; //#TODO make this permissions configurable in the case of non-registrar courses...
$oddRow = TRUE;
$editable = FALSE;
foreach ($classes as $crossListing) { 
	?>
		<tr class="<? print($oddRow ? 'oddRow noBorder' : 'evenRow noBorder'); $oddRow = !$oddRow;?>">
			<td>
			<?php if ($crossListing->getCourseAliasID() == $primaryId) { ?>
				Primary Course
			<?php } else { ?>
				<a class="noWrap buttonLink alignCenter" href="./?cmd=makePrimaryCrossListing&amp;ci=<?php print($this->ci->getId()); ?>&amp;ca=<?php print($crossListing->getCourseAliasId());?>">Make Primary</a>
			<?php } ?>
			</td>
			<?php 
	if (Account_Rd::atLeastStaff() || '' == trim($crossListing->getRegistrarKey())) { 
					$editable = TRUE;
				?>
			<td class="departmentSelectCell">
				<?php $this->getDisplayer()->displayDepartmentSelect($crossListing->getDepartment()->getId(), FALSE, 'crossListings[' . $crossListing->getCourseAliasId() .'][deptId]'); ?>
			</td>
			<td>
				<input name="crossListings[<?php print($crossListing->getCourseAliasID());?>][courseNumber]" type="text" size="5" maxlength="8" value="<?php print($crossListing->getCourseNo());?>">
			</td>
			<td>
				<input name="crossListings[<?php print($crossListing->getCourseAliasID());?>][section]" type="text" size="5" maxlength="8" value="<?php print($crossListing->getSection());?>">
			</td>
			<td>
				<input name="crossListings[<?php print($crossListing->getCourseAliasID());?>][title]" type="text" size="50" value="<?php print($crossListing->getName());?>">
			</td>
			<td>
				<span class="smallestText"><?php print('' != trim($crossListing->getRegistrarKey()) ? $crossListing->getRegistrarKey() : 'none');?></span>
			</td>
			<td>
				<?php 
					if($crossListing->getCourseAliasID() == $primaryId) {
						if ($deletable) { //#TODO ideally, these would be post actions, but the form design makes this tricky
				?>
				<a class="noWrap buttonLink alignCenter" href="./?cmd=deleteClass&amp;ca=<?php print($crossListing->getCourseAliasID()); ?>">Delete</a>
				<?php 
						}
					} else {
				?>
				<a class="noWrap buttonLink alignCenter" href="./?cmd=uncrossListClass&amp;ca=<?php print($crossListing->getCourseAliasID());?>">Uncross-list</a>
				<?php 
					}
				?>
			</td>
			<?php 
	} else { ?>
			<td>
				<?php print($crossListing->getDepartment()->getAbbreviation()); ?>
			</td>
			<td>
				<?php print($crossListing->getCourseNo());?>
			</td>
			<td>
				<?php print($crossListing->getSection());?>
			</td>
			<td>
				<?php print($crossListing->getName());?>
			</td>
			<td>
				<span class="smallestText"><?php print('' != trim($crossListing->getRegistrarKey()) ? $crossListing->getRegistrarKey() : 'none');?></span>
			</td>
			<td></td>
			<?php 
	} ?>
		</tr>
	<?php 
} 
if ($editable) {
	?>
		<tr class="headingRow"><td colspan="7" class="centerContents"><input type="submit" value="Save Changes"></td></tr>
	<?php 
} ?>
	</table>
	<div class="clearing"></div>
</form>
<?php 
/*
		echo "      	<td width=\"8%\" align=\"center\" valign=\"middle\">Primary</td>\n";
		echo "          <td width=\"6%\" align=\"left\" valign=\"top\">&nbsp;</td>\n";
		echo "          <td width=\"4%\" align=\"left\" valign=\"top\">&nbsp;</td>\n";
		echo "          <td width=\"13%\" align=\"left\" valign=\"top\">&nbsp;</td>\n";
		echo "          <td width=\"4%\" align=\"left\" valign=\"top\">&nbsp;</td>\n";
		echo "          <td width=\"8%\" align=\"left\" valign=\"top\">&nbsp;</td>\n";
		echo "          <td width=\"4%\" align=\"left\" valign=\"top\">&nbsp;</td>\n";
		echo "          <td width=\"7%\" align=\"left\" valign=\"top\">&nbsp;</td>\n";
		echo "          <td width=\"13%\" align=\"left\" valign=\"top\">&nbsp;</td>\n";
		echo "          <td width=\"13%\" align=\"left\" valign=\"top\">&nbsp;</td>\n";
		echo "          <td class=\"alignRight\" width=\"11%\" align=\"right\" valign=\"middle\">Delete</td>\n";
		echo "		</tr>\n";
		echo "		<tr class=\"evenRow\">\n";
		echo "			<td align=\"center\" valign=\"middle\"><input name=\"primaryCourse\" type=\"radio\" value=\"".$ci->course->courseAliasID."\" checked></td>\n";
		echo"			<INPUT TYPE=\"HIDDEN\" NAME=\"oldPrimaryCourse\" VALUE=\"".$ci->course->courseAliasID."\">\n";
		echo "          <td align=\"right\" valign=\"middle\" class=\"strong\">Dept:</td>\n";
		echo "          <td align=\"left\" valign=\"middle\">\n";

		self::displayDepartmentSelect($deptID, true, 'primaryDept');

		echo "     		</td>\n";
		echo "          <td align=\"right\" valign=\"middle\">Course#:</td>\n";
		echo "          <td align=\"left\" valign=\"middle\"> <input name=\"primaryCourseNo\" type=\"text\" size=\"5\" maxlength=\"8\" value=\"".$ci->course->getCourseNo()."\"></td>\n";
		echo "          <td align=\"right\" valign=\"middle\">Section:</td>\n";
		echo "          <td align=\"left\" valign=\"middle\"> <input name=\"primarySection\" type=\"text\" size=\"5\" maxlength=\"8\" value=\"".$ci->course->getSection()."\"></td>\n";
		echo "          <td align=\"right\" valign=\"middle\">Title:</td>\n";
		echo "          <td align=\"left\" valign=\"middle\"> <input name=\"primaryCourseName\" type=\"text\" size=\"25\" value=\"".$ci->course->getName()."\"></td>\n";
		echo "          <td align=\"center\" valign=\"middle\"><span class=\"smallestText\">Registrar Key: " . ('' != trim($ci->getRegistrarKey()) ? $ci->getRegistrarKey() : 'none') . "</span></td>\n";
		echo "          <td class=\"alignRight\" align=\"right\" valign=\"middle\"></td>\n";
		echo "		</tr>\n";
		
		$rowNumber = 0;
		for ($i=0; $i<count($ci->crossListings); $i++) 
		{
			$rowClass = ($rowNumber % 2) ? "evenRow" : "oddRow\n";
			echo "		<tr class=\"".$rowClass."\"> \n";
			echo "			<td align=\"center\" valign=\"middle\"><!--<input type=\"radio\" name=\"primaryCourse\" value=\"".$ci->crossListings[$i]->courseAliasID."\">--></td>\n";
			echo "			<td align=\"right\" valign=\"middle\" class=\"strong\">Dept:</td>\n";
			echo "			<td align=\"left\" valign=\"middle\">\n";

			self::displayDepartmentSelect($ci->crossListings[$i]->deptID, true, 'cross_listings['.$ci->crossListings[$i]->courseAliasID.'][dept]');
			
			echo "			<td align=\"right\" valign=\"middle\">Course#:</td>\n";
			echo "			<td align=\"left\" valign=\"middle\"> <input name=\"cross_listings[".$ci->crossListings[$i]->courseAliasID."][courseNo]\" type=\"text\" size=\"5\" maxlength=\"8\" value=\"".$ci->crossListings[$i]->courseNo."\"></td>\n";
			echo "			<td align=\"right\" valign=\"middle\">Section:</td>\n";
			echo "			<td align=\"left\" valign=\"middle\"> <input name=\"cross_listings[".$ci->crossListings[$i]->courseAliasID."][section]\" type=\"text\" size=\"5\" maxlength=\"8\" value=\"".$ci->crossListings[$i]->section."\"></td>\n";
			echo "			<td align=\"right\" valign=\"middle\">Title:</td>\n";
			echo "			<td align=\"left\" valign=\"middle\"> <input name=\"cross_listings[".$ci->crossListings[$i]->courseAliasID."][courseName]\" type=\"text\" size=\"25\" value=\"".$ci->crossListings[$i]->getName()."\"></td>\n";
			echo "          <td align=\"center\" valign=\"middle\"><span class=\"smallestText\">Registrar Key: " . ('' != trim($ci->crossListings[$i]->registrarKey) ? $ci->crossListings[$i]->registrarKey : 'none') . "</span></td>\n";
			echo "			<td class=\"alignRight\" align=\"right\" valign=\"middle\"><input type=\"checkbox\" name=\"deleteCrossListing[".$ci->crossListings[$i]->courseAliasID."]\" value=\"".$ci->crossListings[$i]->courseAliasID."\"></td>\n";
			echo "		</tr>\n";
			$rowNumber++;
		}
		
		echo "		<tr class=\"headingCell1\">\n";
		echo "			<td align=\"left\" valign=\"top\">&nbsp;</td>\n";
		echo "			<td align=\"left\" valign=\"top\">&nbsp;</td>\n";
		echo "			<td align=\"left\" valign=\"top\">&nbsp;</td>\n";
		echo "			<td align=\"left\" valign=\"top\">&nbsp;</td>\n";
		echo "			<td align=\"left\" valign=\"top\">&nbsp;</td>\n";
		echo "			<td align=\"left\" valign=\"top\">&nbsp;</td>\n";
		echo "			<td colspan=\"4\" align=\"left\" valign=\"top\"><div align=\"right\"><input type=\"submit\" name=\"updateCrossListing\" value=\"Update Course Info\">&nbsp;<input type=\"submit\" name=\"deleteCrossListings\" value=\"Delete Selected\"></div></td>\n";
		echo "			<td align=\"left\" valign=\"top\">&nbsp;</td>\n";
		//echo "				<br>\n";
		echo "		</tr>\n";
		echo "  </table>\n";
		echo " </td>\n";
		echo " </tr>\n";
		//echo "</form>\n";
		echo " <tr>\n";
		echo " 	<td height=\"15\">&nbsp;</td>\n";
		echo " </tr>\n";
		//echo " <form action=\"index.php\" method=\"get\">\n";
		echo " <input type=\"hidden\" name=\"cmd\" value=\"editCrossListings\">\n";
		echo " <input type=\"hidden\" name=\"ci\" value=\"".$ci->getCourseInstanceID()."\">\n";
		echo " <tr> \n";
		echo " 	<td>\n";
		echo " 	<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
		echo " 		<tr align=\"left\" valign=\"top\"> \n";
		echo " 			<td width=\"35%\" class=\"headingCell1\">ADD NEW CROSSLISTING</td>\n";
		echo " 			<td>&nbsp;</td>\n";
		echo " 		</tr>\n";
		echo " 	</table>\n";
		echo " 	</td>\n";
		echo " </tr>\n";		
		
		//SELECT EXISTING COURSE
		echo "		<tr> \n";
		echo "			<td align=\"left\" valign=\"top\" class=\"borders\" colspan=\"8\">\n";
		echo "     			<tr class=\"headingCell1\">\n";
		echo "      			<td colspan=\"8\" align=\"left\">SELECT EXISTING COURSE</td>\n";
		echo "				</tr>\n";		
		echo "			</td>\n";
		echo "	</td>\n";
		echo "</tr>\n";				
		
		//echo "   	</table>\n";
		//echo "		</td>\n";
		//echo " 	</tr>\n";		

		if (!isset($_REQUEST['xlist_new_course']))
		{
			//give list of possible xlistings or class selecter for staff or greater
			echo "</form>\n"; //close form so that class lookup will work
			self::displaySelectClass($cmd, $potential_xlistings, '', array('ci'=>$_REQUEST['ci'], 'addCrossListing' => 'true'), false, 'xlist_ci', 'index.php?cmd=editCrossListings&xlist_new_course=true&ci='.$ci->getCourseInstanceID(), null, array($ci->getCourseInstanceID()));
		} else {
		//Create New Course
			echo "<tr> "
			."    	<td align=\"left\" valign=\"top\" class=\"borders\">\n"
			."    	<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">\n"
			."      	<tr class=\"headingCell1\">"
			."          	<td colspan=\"8\" align=\"left\">CREATE NEW COURSE</td>\n"	
			."			</tr>\n"
			."          <tr> "
			."          	<td align=\"left\" valign=\"middle\" class=\"strong\"><div align=\"center\">Department:</div></td>\n"
			."              <td align=\"left\" valign=\"middle\">\n";
			
			self::displayDepartmentSelect(null, true, 'newDept');
	
			echo "          <td align=\"left\" valign=\"middle\" class=\"strong\"><div align=\"center\">Course Number:</div></td>\n"
			."              <td align=\"left\" valign=\"middle\"> <div align=\"left\"><input name=\"newCourseNo\" type=\"text\" id=\"Title2\" size=\"4\" maxlength=\"6\"></div></td>\n"
			."              <td align=\"left\" valign=\"middle\" class=\"strong\"><div align=\"center\">Section:</div></td>\n"
			."              <td align=\"left\" valign=\"middle\"> <div align=\"left\"><input name=\"newSection\" type=\"text\" size=\"4\" maxlength=\"6\"></div></td>\n"
			."              <td align=\"left\" valign=\"middle\" class=\"strong\"><div align=\"center\">Title:</div></td>\n"
			."          	<td align=\"left\" valign=\"middle\"> <div align=\"left\"><input name=\"newCourseName\" type=\"text\" size=\"30\"></div></td>\n"
			."			</tr>\n";	
			
			echo "      <tr class=\"headingCell1\">\n";
			echo "          <td align=\"left\" valign=\"middle\" colspan=\"8\"><div align=\"right\"><input type=\"submit\" name=\"addCrossListing\" value=\"Add Cross-listing\"></div></td>\n";
			echo "   	</tr>\n";				
		}

		
		echo "<tr>\n"
		."          <td>&nbsp;</td>\n"
		."        </tr>\n"
		."        <tr>\n"
		."          <td><div align=\"center\"><a href=\"index.php?cmd=editClass&ci=".$ci->courseInstanceID."\">Return to Edit Class</a></div></td>\n"
		."        </tr>\n"
		."        <tr>\n"
		."          <td><img src=\"public/images/spacer.gif\" width=\"1\" height=\"15\"></td>\n"
		."        </tr>\n"
		." </table>\n";
		echo "</form>\n";
*/

$this->getDisplayer()->displayCoursePicker($this->coursePickerModel);